package day_2022_7_to_8.day48;

import java.util.Stack;

/**
 * @author haomin
 * @date 2022/08/30 11:16
 **/
public class Day45_2_Offer09_CQueue {
    class CQueue {
        Stack<Integer> stack1;
        Stack<Integer> stack2;
        public CQueue() {
            stack1 = new Stack<>();
            stack2 = new Stack<>();
        }

        public void appendTail(int value) {
            stack1.add(value);
        }

        public int deleteHead() {
            if(!stack2.isEmpty()){
                return stack2.pop();
            }else {
                while(!stack1.isEmpty()){
                    stack2.add(stack1.pop());
                }
                return stack2.isEmpty() ? -1 : stack2.pop();
            }
        }
    }
}